import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/models/xindong_auth_class.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/common/xindong_round_image.dart';

class XinDongAuthItemWidget extends StatelessWidget {
  final XinDongAuthClass model;
  final Function(XinDongAuthClass model) onTap;

  const XinDongAuthItemWidget({super.key, required this.model, required this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => onTap(model),
      behavior: HitTestBehavior.opaque,
      child: Container(
        margin: const EdgeInsets.only(left: 15, right: 15, bottom: 10),
        padding: const EdgeInsets.all(15),
        decoration: BoxDecoration(color: DZColors.cellColor, borderRadius: BorderRadius.circular(16)),
        child: Row(
          children: [
            XinDongRoundImage(url: model.icon, size: 46,radius: 46),
            const SizedBox(width: 15),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    model.title,
                    style: const TextStyle(fontSize: 16, color: DZColors.titleColor),
                  ),
                  if (model.status != 2 && int.parse("${model.reward}") > 0)
                    Padding(
                      padding: const EdgeInsets.only(top: 3),
                      child: Text(
                        "赠送${model.reward}金币",
                        style: TextStyle(fontSize: 12, color: DZColors.hexStringColor("F0963D")),
                      ),
                    ),
                ],
              ),
            ),
            _buildStatusWidget(model),
          ],
        ),
      ),
    );
  }

  _buildStatusWidget(XinDongAuthClass model) {
    if (model.status == 0) {
      return Container(
        height: 26,
        alignment: Alignment.center,
        padding: const EdgeInsets.only(left: 12, right: 12),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(26),
          // 渐变色
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [DZColors.hexStringColor("#F97FF8"), DZColors.hexStringColor("#FAB0CA")],
          ),
        ),
        child: const Text("去认证", style: TextStyle(fontSize: 14, color: Colors.white, height: 1.2)),
      );
    } else if (model.status == 1 || model.status == 3) {
      return Container(
        height: 26,
        alignment: Alignment.center,
        padding: const EdgeInsets.only(left: 12, right: 12),
        decoration: BoxDecoration(
          color: DZColors.disabledGreyColor,
          borderRadius: BorderRadius.circular(26),
        ),
        child: Text(
          model.status == 1 ? "审核中" : "审核未通过",
          style: const TextStyle(fontSize: 14, color: Colors.white, height: 1.2),
        ),
      );
    } else if (model.status == 2) {
      return Container(
        child: ImageUtil.asset(AssetsRes.ICON_AUTHENTICATION_CERTIFIED),
      );
    }
    return const SizedBox();
  }
}
